// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0

import { EditorPalette, EditorAnimationSettings } from "./styling.slint";
import { Palette } from "std-widgets.slint";

export component StateLayer {
    // styling
    in property <length> border-radius <=> state-layer.border-radius;

    // states
    in property <bool> pressed;
    in property <bool> has-hover;
    in property <bool> has-focus;
    in property <length> focus-padding: 2px;
    focus-border := Rectangle {
        x: (root.width - self.width) / 2;
        y: (root.height - self.height) / 2;
        width: root.width + 2 * root.focus-padding;
        height: root.height + 2 * root.focus-padding;
        border-radius: state-layer.border-radius + root.focus-padding;
        border-width: 1px;
        border-color: Palette.accent-background;
        opacity: 0;

        states [
            focused when root.has-focus: {
                opacity: 1;
            }
        ]

        animate opacity { duration: EditorAnimationSettings.color-duration; }
    }

    state-layer := Rectangle {
        width: 100%;
        height: 100%;

        animate background { duration: EditorAnimationSettings.color-duration; }
    }

    states [
        pressed when root.pressed: {
            state-layer.background: EditorPalette.state-pressed;
        }
        hovered when root.has-hover: {
            state-layer.background: EditorPalette.state-hovered;
        }
    ]
}
